package fr.soat.agileconference2010.constructeurcher;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class DictionnaireFactory {
  public static Dictionnaire buildFromTextFile() throws IOException {
    Map<String, String> definitions = new HashMap<String, String>();
    File file = new File("francais.txt");
    BufferedReader reader = new BufferedReader(new FileReader(file));
    String ligne;
    while ((ligne = reader.readLine()) != null) {
      String[] tableauLigne = ligne.split(":");
      definitions.put(tableauLigne[0], tableauLigne[1]);
    }
    return new DictionnaireTestable(definitions);
  }
  
  public static Dictionnaire buildFromTextFile(String nomFichier) throws IOException {
    Map<String, String> definitions = new HashMap<String, String>();
    File file = new File(nomFichier);
    BufferedReader reader = new BufferedReader(new FileReader(file));
    String ligne;
    while ((ligne = reader.readLine()) != null) {
      String[] tableauLigne = ligne.split(":");
      definitions.put(tableauLigne[0], tableauLigne[1]);
    }
    return new DictionnaireTestable(definitions);
  }
}
